package com.mall.controller;

import com.mall.domain.Permission;
import com.mall.service.IPermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 权限web层
 * @author : liangY
 * @date : 2020-12-26 11:51
 */
@RequestMapping("/permissions")
@Controller
public class PermissionController {

    @Autowired
    private IPermissionService permissionService;

    /**
     * 渲染树形菜单
     * @param
     * @return
     */
    @RequestMapping("/menus")
    public  @ResponseBody

    Map<String,Object> getMenus(HttpServletRequest request) {

        Integer role_id = Integer.parseInt(request.getParameter("role_id"));
        Map<String,Object> menusMap = new HashMap<>();
        //获取菜单集合
        List<Permission> menus = permissionService.getTree2(role_id);
        //放入Map集合
        menusMap.put("data",menus);
        //创建状态Map
        Map<String,Object> metaMap = new HashMap<>();
        metaMap.put("msg","获取菜单列表成功");
        metaMap.put("status",200);
        menusMap.put("meta",metaMap);

        return menusMap;
    }

    /**
     * 查询所有权限集合
     * @param
     * @return
     */
    @RequestMapping("/list")
    public  @ResponseBody
    Map<String,Object> getList() {
        Map<String,Object> listMap = new HashMap<>();
        //获取权限集合
        List<Permission> list = permissionService.getList();
        //放入Map集合
        listMap.put("data",list);

        //创建状态Map
        Map<String,Object> metaMap = new HashMap<>();
        metaMap.put("msg","获取权限列表成功");
        metaMap.put("status",200);

        listMap.put("meta",metaMap);
        return listMap;
    }
}
